home *** CD-ROM | disk | FTP | other *** search
- /* Copyright, 1990, Regents of the University of Colorado */
- /* This program computes a matrix - vector product, dividing the matrix into
- * columns, with multiple columns per processor. The matrix is of size M x N,
- * where N must be a multiple of P. */
-
- #include "dino.h"
-
- #define P 3
- #define M 16
- #define N 9
-
- environment node[P:id] {
-
- composite matvec (in a, in x, out y)
- double distributed a[M][N] map BlockCol; /* Input matrix */
- double distributed x[N] map Block; /* Input vector */
- double distributed y[M] map all; /* Result vector */
-
- {
- int i, j; /* Looping variable */
-
- /* Each processor computes a contribution to the final result y[] */
- for (i = 0; i < M; i++) {
- y[i] = 0;
- for (j = id * N/P; j < (id + 1) * N/P; j++)
- y[i] += a[i][j] * x[j];
- }
-
- /* Now, we do a sum across all processors to compute the final result */
- y[] = gsum(y[])#;
-
- }
- }
-
- environment host {
-
- double a[M][N];
- double x[N];
- double y[M];
-
- void main ()
-
- {
- int i, j; /* Looping variables */
-
- /* Set up the initial data for a[][] and v[] */
- for (j = 0; j < N; j++) {
- x[j] = j;
- for (i = 0; i < M; i++)
- a[i][j] = i + j;
- }
-
- /* Print out the initial data */
- printf ("Initial data for a:\n");
- for (i = 0; i < M; i++) {
- for (j = 0; j < N; j++)
- printf ("%6.2f", a[i][j]);
- printf ("\n");
- }
-
- printf ("\nInitial data for x:\n");
- for (i = 0; i < N; i++)
- printf ("%6.2f\n", x[i]);
-
- /* Perform the computation */
- matvec (a[][], x[], y[])#;
-
- /* Printout the resulting vector y */
- printf ("\nResult data for y:\n");
- for (i = 0; i < M; i++)
- printf ("%6.2f\n", y[i]);
- }
- }
-